// pages/monthlymall/monthlymall.js
var _swit = require('../../utils/swit.js');

var url = "http://www.imooc.com/course/ajaxlist?page=0&sort=last";
// var page = 0;
// var sort = "last";
var Getlist = function (that) {

  that.setData({
    hidden: false
  });
  wx.request({
    url: url,
    data: {
      // page:page,
      // sort:sort
    },
    header: {
      'content-type': 'application/json'
    },
    success: function (res) {
      var list = that.data.list;
      for (var i = 0; i < 8; i++) {
        list.push(res.data.list[i])
      }
      that.setData({
        list: list,
        hidden: true
      });
      that.data.page++;

    }
  });
}
Page({
  data: {
    hidden: true,
    list: [],
    scrollTop: 0,
    scrollHeight: 0,
    page: 0
  },
  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        console.info(res.windowHeight);
        that.setData({
          scrollHeight: res.windowHeight
        });
      }
    });
  },
  onReady: function () {
    // 页面渲染完成
  },
  onShow: function () {
    // 页面显示
    var that = this;
    Getlist(that);
  },
  onHide: function () {
    // 页面隐藏
  },

  onUnload: function () {
    // 页面关闭
  },
  onItemClick: function (e) {
    console.log(e);
    _swit.swit("../monthlymalldetail/monthlymalldetail");
  }
})